class Account < ActiveRecord::Base
  belongs_to:user
  has_many:account_record
  
  def self.transfer!(amount,sender,reciever)
    #sender=Account.find(options['sender'])
    #reciever=Account.find(options['reciever'])
    if sender&&reciever&&amount>0
       if sender.account_money < amount
         return false
       else
           sd=sender.account_money-amount
           rcv=reciever.account_money+amount
           sender.update_attributes!(:account_money=>sd)||raise(ActiveRecord::RecordNotSaved)
           reciever.update_attributes!(:account_money=>rcv)||raise(ActiveRecord::RecordNotSaved)       
      end
       
    end
  end
  
  def add_money(money)
    self.account_money+=money
  end
  
end
